package com.qing.administer.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qing.administer.annotations.ResponseResult;
import com.qing.administer.annotations.WebLog;
import com.qing.administer.entity.SysMenu;
import com.qing.administer.pojo.vo.SysMenuVO;
import com.qing.administer.pojo.vo.TreeVO;
import com.qing.administer.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 菜单管理 前端控制器
 * </p>
 *
 * @author qing
 * @since 2021-09-17
 */
@Api(tags = "菜单管理")
@ResponseResult
@RestController
@RequestMapping("/administer/sys-menu")
public class SysMenuController {

	
	@Autowired
	private SysMenuService sysMenuService;
	

	@WebLog("列表")
	@ApiOperation(value = "列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "current",value = "当前页",required = true,defaultValue = "1"),
			@ApiImplicitParam(name = "size",value = "每页显示条数",required = true,defaultValue = "10"),
			@ApiImplicitParam(name = "status",value = "是否启用：1：启用 0：禁用",required = false),
			@ApiImplicitParam(name = "keyword",value = "模糊匹配",required = false)
	})
	@GetMapping("/page")
	public IPage<SysMenu> getPage(@RequestParam(value = "current",defaultValue = "1",required = false) Long current,
								  @RequestParam(value = "size",defaultValue = "10",required = false) Long size,
								  @RequestParam(value = "status",defaultValue = "",required = false) Integer status,
								  @RequestParam(value = "keyword",defaultValue = "",required = false) String keyword){

		return sysMenuService.findPage(current,size,status,keyword);
	}

	@WebLog("简易菜单树")
	@ApiOperation(value = "简易菜单树")
	@GetMapping("/tree")
	public List<TreeVO> findMenuTree(){
		return  sysMenuService.findMenuTree();
	}


	@WebLog("全信息菜单树")
	@ApiOperation(value = "全信息菜单树")
	@GetMapping("/tree-all")
	public List<SysMenuVO> findSysMenu(){
		return  sysMenuService.findSysMenu();
	}


	@WebLog("编辑")
	@ApiOperation(value = "编辑")
	@PostMapping
	public Boolean edit(@RequestBody SysMenu sysMenu){
		return  sysMenuService.saveOrUpdate(sysMenu);
	}


	@WebLog("删除")
	@ApiOperation(value = "删除")
	@ApiImplicitParam(name = "id",value = "Id",required = true)
	@DeleteMapping
	public Boolean delete(@RequestParam(value = "id") Long id){
		return sysMenuService.removeById(id);
	}
	
}

